<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="<?=site_url('shops')?>">首页</a>
                <span class="crumb-step">&gt;</span><span class="crumb-name">商品管理</span>
            </div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="<?=site_url('shops/goods/czurl')?>" method="post">
                    <table class="search-tab">
                        <tr>
                            <th width="120">选择分类:</th>
                            <td id="sort">
                                <?php foreach($sort_list as $k => $v): ?>
                                <select name="search-sort" id="catid" class="required top_<?=$k?>" onchange="getsort(<?=$k?>,this.value)">
                                    <option value="<?=$v['pid']?>">--<?=$v['pid'] == 0 ? '顶级分类' : '上级分类'  ?>--</option>
                                    
                                    <?php foreach ($v['content'] as $key => $value):?>
                                    <option value="<?=$value['id']?>" <?=$value['id'] == $v['id'] ? 'selected' : ''?> ><?=$value['name']?></option>
                                    <?php endforeach;?>
                                </select>
                                <?php endforeach;?>
                            </td>
                            <th width="70">关键字:</th>
                            <td><input class="common-text" placeholder="商品名称、品牌名称" name="keywords" value="<?=empty($_GET['keywords']) ? '' : $_GET['keywords']?>" id="" type="text"></td>
                            <td><input class="btn btn-primary btn2" name="cx" value="查询" type="submit"></td>
                            <td><a class="btn btn-primary btn2" onclick="location.href='<?=site_url('shops/goods/index')?>'">重置</a></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="<?=site_url('shops/goods/create')?>"><i class="icon-font"></i>新增商品</a>
                        <a id="batchDel" href="javascript:void(0)"><i class="icon-font"></i>批量删除</a>
                        <a id="updateOrd" href="javascript:void(0)"><i class="icon-font"></i>更新排序</a>
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="5%"><input class="allChoose" name="" type="checkbox"></th>
                            <th>分类</th>
                            <th>品牌名称</th>
                            <th>商品名称</th>
                            <th><a href="<?=site_url('shops/goods/index?'.$order_url.'sort=sort_num_'.$order) ?>">商品数量</a></th>
                            <th><a href="<?=site_url('shops/goods/index?'.$order_url.'sort=sort_sales_'.$order) ?>">产品销量</a></th>
                            <th><a href="<?=site_url('shops/goods/index?'.$order_url.'sort=sort_price_'.$order) ?>">商品价格</a></th>
                            <th><a href="<?=site_url('shops/goods/index?'.$order_url.'sort=sort_sprice_'.$order) ?>">底价</a></th>
                            <th><a href="<?=site_url('shops/goods/index?'.$order_url.'sort=sort_time_'.$order) ?>">上架时间</a></th>
                            <th>操作</th>
                        </tr>
                        <?php foreach($list as $key => $value):?>
                        <tr>
                            <td class="tc"><input name="id[]" value="59" type="checkbox"></td>
                            <td><?=$value['sort_name']?></td>
                            <td><?=$value['brand']?></td>
                            <td title="查看商品详情"><?=$value['name']?></td>
                            <td><?=$value['num']?></td>
                            <td><?=$value['sales']?></td>
                            <td><?=$value['price']?></td>
                            <td><?=$value['sprice']?></td>
                            <td><?=date('Y-m-d',$value['shelves'])?></td>
                            <td>
                                <a class="link-update" href="<?=site_url('shops/goods/update?gid='.$value['id'])?>">修改</a>
                                <a class="link-del" href="javascript:void(0);" onclick="del_goods('<?=$value['id']?>')">删除</a>
                            </td>
                        </tr>
                        <?php endforeach;?>
                        
                    </table>
                    <div class="list-page"><?=$page?></div>
                </div>
            </form>
        </div>
<script>
    function getsort(top,pid){
        
        //删除
        var k = top*1+1;
        $("#sort select").each(function(){
            $(".top_"+k).remove();
            k ++;
        })
        if(pid == 0){
            return false;
        }
        
        //判断是否是上级分类
        var sv = $(".top_"+(top*1-1)).val();
        if(sv === pid){
            return false;
        }
        
        $.post("<?=site_url('shops/sort/getsort')?>",{sid:pid},function(data){
            if(data == ''){
                return false;
            }
            var l = '<select name="search-sort" id="catid" class="required top_'+(top*1+1)+'" onchange="getsort('+(top*1+1)+',this.value)">';
            l += '<option value="'+pid+'">--上级分类--</option>';
            $(data).each(function(){
                l += '<option value="'+this.id+'">'+this.name+'</option>';
            })
            l += '</select>';
            $(".top_"+top).after(l);
        },'json');
    }

    function del_goods(gid){
        alert(gid);
        $.post("<?=site_url('shops/goods/delete')?>",{gid:gid},function(res){
            if(res == 1){
                location.reload(true);
            }else{
                layer.alert(res,{
                    icon:2,
                });
            }
        });
    }

</script>